<!DOCTYPE html>
<html>

<div th:replace="common/jsCssRef :: jsfJsCssRef"></div>

<body class="bgf6">

<div th:replace="common/head :: jsfHeader"></div>

<div class="main-body pb100">
    <div class="container pt10">
        <div class="dflx sbt">
            <div th:replace="common/left :: jsfLeft"></div>

            <div class="body-right">
                <div class="bread-nav bgff">
                    <ul class="dflx">
                        <li><a href="###">首页</a></li>
                        <li><a href="###">统筹规划</a></li>
                        <li><a href="/view/developPlan">全市发展规划</a></li>
                    </ul>
                </div>

                    <div class="bgff mt10" id="app">
                        <div class="wrap">
                            <!--筛选条件/操作-->
                            <div class="row">
                                <div class="col-md-4">
                                    <input type="text" class="form-control" id="planNumber" placeholder="请输入项目名">
                                </div>
                                <div class="col-md-4">
                                    <select class="form-control c999" id="originUnit">
                                        <option disabled selected class='none' value="">请选择编制单位</option>
                                        <option value="1">长沙</option>
                                        <option value="2">武汉</option>
                                        <option value="3">南京</option>
                                        <option value="4">上海</option>
                                    </select>
                                </div>
                                <div class="col-md-4">
                                    <div class="input-group">
                                        <input type="text" class="form-control" placeholder="请选择编制时间" id="datepicker">
                                    </div>
                                </div>

                            </div>

                            <div class="row mt15">
                                <div class="col-md-4">
                                    <select class="form-control c999" id="planStatus">
                                        <option class='none' value="">请选择规划状态</option>
                                        <option value="1">草稿</option>
                                        <option value="2">已提交</option>
                                        <!--<option value="3">审定通过</option>-->
                                        <!--<option value="4">审定不通过</option>-->
                                        <!--<option value="5">批准通过</option>-->
                                        <!--<option value="6">批准不通过</option>-->
                                    </select>
                                </div>
                                <div class="col-md-4 col-md-offset-4 tr">
                                    <button type="button" id="search" class="btn btn-primary f12" @click="loadPlanList()"> 查询</button>
                                    <button type="button" id="reset" class="btn btn-white f12" onclick="resetParam()"> 重置</button>
                                </div>
                            </div>
                            <form/>

                            <div class="mt30 dflx sbt">
                                <button type="button" onclick="toAddPlan();" class="btn btn-primary f12"> 新增编制规划</button>
                                <div class="">
                                    <button type="button" class="btn btn-white f12"> 批量导入</button>
                                    <button type="button" class="btn btn-white f12" @click="delMore"> 批量删除</button>
                                </div>
                            </div>

                            <!--表格部分-->
                            <table class="table th52 f14 table-bordered mt20 table-hover" id="cityPlanTable">
                                <template>
                                    <el-table
                                            ref="multipleTable"
                                            :data="plans"
                                            tooltip-effect="dark"
                                            style="width: 100%"
                                            @selection-change="handleSelectionChange">

                                        <el-table-column
                                                type="selection"
                                                width="55">
                                        </el-table-column>
                                        <el-table-column
                                                label="序号"
                                                width="60">
                                            <template slot-scope="scope">{{ scope.row.planId }}</template>
                                        </el-table-column>
                                        <el-table-column
                                                prop="planName"
                                                label="规划名称"
                                                width="150">
                                        </el-table-column>
                                        <el-table-column
                                                prop="planNo"
                                                label="规划编号"
                                                width="150">
                                        </el-table-column>
                                        <el-table-column
                                                prop="compileTime"
                                                label="编制时间"
                                                :formatter="sliceTime"
                                                width="120">
                                        </el-table-column>
                                        <el-table-column
                                                prop="compileUnit"
                                                label="编制单位"
                                                width="120">
                                        </el-table-column>
                                        <el-table-column
                                                label="当前状态"
                                                width="120">
                                            <template slot-scope="scope"><i v-bind:class="[scope.row.currentState == 1 ? 'org' : 'gre', 'fa', 'fa-circle']"></i> {{  planStatus(scope.row.currentState) }}</template>
                                        </el-table-column>
                                        <el-table-column label="操作">
                                            <template slot-scope="scope">
                                                <el-link type="primary" :href="'/view/detailPlan?id=' + scope.row.planId">查看</el-link>
                                                <el-link type="primary" :href="'/view/editDevelopPlan?id=' + scope.row.planId">编辑</el-link>
                                                <el-link type="primary" @click="delPlan(scope.row.planId)">删除</el-link>
                                            </template>
                                        </el-table-column>
                                    </el-table>
                                </template>

                            </table>

                            <!--表格尾部-->
                            <div class="dflx aic sbt pb20">
                                <el-pagination
                                        @size-change="handleSizeChange"
                                        @current-change="handleCurrentChange"
                                        :current-page="currentPage"
                                        :page-sizes="[2, 3, 4]"
                                        :page-size="2"
                                        layout="total, sizes, prev, pager, next, jumper"
                                        :total="totalPage">
                                </el-pagination>
                            </div>

                        </div>
                    </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">

    $(document).ready(function () {
        $('#city').addClass('active');
    });
    
    function toAddPlan() {
        window.location.href = contentPath + '/view/addCityPlan';
    }


    var statusPlanObj = {
        '1' : '草稿',
        '2' : '已提交',
        '3' : '审定通过',
        '4' : '审定不通过',
        '5' : '批准通过',
        '6' : '批准不通过'
    }
    

    var appPage = new Vue({
        el : '#app',
        data : {
            plans:[],
            multipleSelection: [],
            currentPage : 1,
            totalPage : 1,
            pageSize : 2
        },
        created : function() {
            this.loadPlanList();
        },
        computed : {

        },
        methods : {
            sliceTime(row, column) {
                return row.compileTime.slice(0, 10);
            },
            loadPlanList : function () {
                let that = this;
                $.ajax({
                    'url' : contentPath + '/cityPlan/getList',
                    'dataType' : 'json',
                    'type' : 'get',
                    'data' : {
                        pageSize: that.pageSize,   //页面大小originUnit
                        pageNumber: that.currentPage,//页码
                        planName: $("#planNumber").val(),
                        compileUnitId: $('#originUnit option:selected').val(),
                        compileTime: $("#datepicker").val(),
                        currentState: $('#planStatus option:selected').val()
                    },
                    'success' : function (result) {
                        if (result.code != 1000) {
                            alert(result.message);
                            return;
                        }

                        appPage.plans = result.data.records;
                        appPage.totalPage = result.data.total;
                    },
                    'error' : function (result) {
                    }
                });
            },
            handleSelectionChange :  function (val) {
                this.multipleSelection = val;
            },

            //1-草稿 2-已提交 3-审定通过 4-审定不通过 5-批准通过 6-批准不通过
            planStatus : function (val) {

                return statusPlanObj[val];
            },

            handleSizeChange : function(val) {
                this.pageSize = val;
                this.loadPlanList();
            },

            handleCurrentChange : function(val) {
                this.currentPage = val;
                this.loadPlanList();
            },
            
            delPlan : function (val) {
                this.$confirm('此操作将永久删除该项目, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    delPlanSign(val);

            }).catch(() => {
                    this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
            },
            
            delMore: function () {
                let selectedList = this.$refs.multipleTable.selection;
                console.log(selectedList);
                if(selectedList.length==0){
                    return;
                }
                let ids = "";
                selectedList.forEach(item=>{
                    ids+=item.planId+",";
                });
                ids = ids.substring(0, ids.length - 1);
                this.$confirm('此操作将永久删除这些项目, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        $.ajax({
                            'url' : contentPath + '/cityPlan/deleteList',
                            'dataType' : 'json',
                            'type' : 'post',
                            'data' : {
                                'ids' : ids
                            },
                            'success' : function (result) {
                                if (result.code != 1000) {
                                    alert(result.message);
                                    return;
                                }

                               window.location.reload();
                            },
                            'error' : function (result) {
                            }
                        });

                }).catch(() => {
                        this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });



            }
        }
    })
    
    function resetParam() {
        $("#planNumber").val("")
        $("#datepicker").val("")
        document.getElementById("planStatus").options[0].selected = true;
        document.getElementById("originUnit").options[0].selected = true;
    }
    
    function delPlanSign(planId) {
        $.ajax({
            'url' : contentPath + '/cityPlan/delete',
            'dataType' : 'json',
            'type' : 'get',
            'data' : {
                'planId' : planId
            },
            'success' : function (result) {
                if (result.code != 1000) {
                    alert(result.message);
                    return;
                }

                window.location.reload();
            },
            'error' : function (result) {
            }
        });
    }


    $('#datepicker').fdatepicker({
        format: 'yyyy-mm-dd'
    });


</script>
</body>
</html>